#include <app\states\connectionState.h>
#include <app\states\statesFactory.h>

int connectionState::class_type_id = CONNECTION_STATE_TYPE_ID;

REGISTER_STATE(CONNECTION_STATE_TYPE_ID, connectionState);

sessionState *
connectionState::create() {
  return new connectionState();
} 

string 
connectionState::getPassword() {
  return password;
}

void 
connectionState::setPassword(string _password) {
  password = _password;
}

string 
connectionState::getUserName() {
  return user_name;
}

void
connectionState::setUserName(string _user_name) {
  user_name = _user_name;
}

string 
connectionState::getModelName() {
  return model_name;
}

void 
connectionState::setModelName(string _model_name) {
  model_name = _model_name;
}

void 
connectionState::reset() {
  internal_state = INIT_STATE;
}

void
connectionState::setConnectionEstablished(bool value) {
  if (value) internal_state = CONNECTION_ESTABLISHED;
  else internal_state = CONNECTION_NOT_ESTABLISHED;
}

void 
connectionState::setLoginAccepted(bool value) {
  if (value) internal_state = LOGIN_ACCEPTED;
  else internal_state = LOGIN_REJECTED;
}

bool 
connectionState::waitForConnection() {
  return internal_state == INIT_STATE;
}

bool 
connectionState::waitForLogin() {
  return !(internal_state == LOGIN_ACCEPTED || internal_state == LOGIN_REJECTED);
}

bool 
connectionState::isConnectionEstablished() {
  return internal_state == CONNECTION_ESTABLISHED;
}

bool 
connectionState::isLoginAccepted() {
  return internal_state == LOGIN_ACCEPTED;
}

int 
connectionState::getClassTypeId() {
  return connectionState::class_type_id;
}

int
connectionState::getTypeId() {
  return type_id;
}

connectionState::connectionState() : type_id(CONNECTION_STATE_TYPE_ID), internal_state(INIT_STATE), model_name(""), user_name(""), password("") {
}

connectionState::connectionState(ESTATE value) : 
  type_id(CONNECTION_STATE_TYPE_ID), internal_state(value) {
}

connectionState::~connectionState() {

}